package com.umakr.demo.controller;

import com.umakr.demo.model.Banji;
import com.umakr.demo.model.BanjiStudent;
import com.umakr.demo.model.Student;
import com.umakr.demo.service.BanjiSerivice;
import com.umakr.demo.service.BanjiStudentService;
import com.umakr.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangliu on 2017/8/22.
 */
@Controller
@RequestMapping("/BanjiStudentController")
public class BanjiStudentController {
    @Autowired
    BanjiStudentService banjiStudentService;

    @Autowired
    BanjiSerivice banjiSerivice;

    @Autowired
    StudentService studentService;

    @RequestMapping("/showBanjiStudent")
    public String showBanjiStudent(){
        return "StudentManage/banjistudent";
    }

    @RequestMapping("/banjiDate")
    @ResponseBody
    public List banjiDate(){
        List<Banji> list = banjiSerivice.showAll();
        return list;

    }



    @RequestMapping("/studentDate")
    @ResponseBody
    public List studentDate(){
        List<Student> list = studentService.showStudent();
        return list;
    }

    @RequestMapping("/banjiShowStudent")
    @ResponseBody
    public List banjiShowStudent(Long bid){
        List<Student> list = banjiStudentService.banjiShowStudent(bid);
        return list;
    }

    @RequestMapping("/allSelectedStudent")
    @ResponseBody
    public void allSelectedStudent(Long bid, @RequestParam(value ="str[]",required = false)String str[]){
//        首先删除所有数据
        banjiStudentService.deleteAll(bid);
        for (int i =0;i<str.length;i++){
            BanjiStudent banjiStudent = new BanjiStudent(bid,Long.parseLong(str[i]));
            banjiStudentService.addAll(banjiStudent);
        }

    }



}
